home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
- Newsgroups: comp.lang.c
- Subject: Re: Help with gettng 2 chars into an integer!
- Date: Thu, 11 Jan 1996 13:33:48 GMT
- Organization: Carelcomp Forest Oy
- Message-ID: <4d340d$kia@tahko.lpr.carel.fi>
- References: <4d2eh1$7pm@usc.edu>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- X-Newsreader: Forte Free Agent 1.0.82
-
- wawda@scf.usc.edu (Abu Wawda) wrote:
-
-
- >Hi. I can't seem to figure out how to do this. Basically I have to chars that
- >I want to put into a 2-byte integer. It seems easy at first, but I can't seem
- >to figure out to do it with the bit-fidling operators (shifting or masking).
- >Simple put, I'd like to do:
-
- > char a,b;
- > int c;
-
- > a = 'A';
- > b = 'B';
- > c = ? /* the first byte in c should contain the value of a, and the
- >second byte should contain the value of b */
-
- >Please help! Thanks in advance,
-
- Try something like:
-
- #define MAKEWORD(a, b) (((int)a << 8) | (int)b)
-
- Or, if you want them the other way around:
-
- #define MAKEWORD(a, b) (((int)b << 8) | (int)a)
-
- Later,
- AriL
-
- All my opinions are mine and mine alone.
-
-